package com.liumo.domain;

import com.liumo.domain.intface.BinaryOperation;

import java.util.ArrayList;
import java.util.Scanner;

public class OperationBase{
    public static ArrayList<BinaryOperation> adds;
    public static ArrayList<BinaryOperation> lows;

    /**
     * 该类当作工具类，将BUtil的生成的adds，lows传入专门做练习的操作
     */

    /**
     *      调用该静态方法进行练习
     *      流程为，算数生成工具生成算式至adds,lows中
     *      将两集合导入至该工具类中，使用Binary的父类方法获取算数基
     * @param adds
     * @param lows
     * @param scan
     */
    public static void practice(ArrayList<BinaryOperation> adds, ArrayList<BinaryOperation> lows, Scanner scan){
        int grade = 0;
        if (!adds.isEmpty()){
            System.out.println("-----------------下面是加法练习计算，请输入数字答案，进行打分------------------");
            for (BinaryOperation bo : adds){
                System.out.print(bo.getBinaryBaseStr());
                int result = scan.nextInt();
                bo.setResult(result);
                bo.createBinaryOperation();
                if (result == bo.getResult())
                    grade++;
            }
        }
        if(!lows.isEmpty()){
            System.out.println("-----------------下面是减法练习计算，请输入数字答案，进行打分------------------");
            for (BinaryOperation bo : lows){
                System.out.print(bo.getBinaryBaseStr());
                int result = scan.nextInt();
                bo.setResult(result);
                bo.createBinaryOperation();
                if (result == bo.getResult())
                    grade++;
            }
        }
        System.out.println("你本次练习的总分为: " + grade);
        System.out.println("本次判题为电脑自动判题, 若想老师判题，请按1,将习题结果保存至本地等待老师判题，按0退出");
        if (scan.nextInt() == 0){
            System.out.println("退出成功,期待你的下次练习");
            return;
        }
        System.out.println("保存成功");
    }
}
